class Solution {
    public int[] dailyTemperatures(int[] temperatures) {
        int[] answer = new int[temperatures.length];
        LinkedList<Integer> stack = new LinkedList<>();
        int e;
        for (int i = 0; i < temperatures.length; i++){
            answer[i] = 0;
            while (stack.size() != 0 && temperatures[i] > temperatures[stack.getLast()]){
                e = stack.removeLast();
                answer[e] = i - e;
            }
            stack.add(i);
        }
        return answer;
    }
}